package it.giuseppetrisciuoglio.lyrics.persistence.entity;

import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.Lob;
import javax.persistence.ManyToOne;
import javax.persistence.PrePersist;
import javax.persistence.PreUpdate;
import javax.persistence.Table;
import javax.persistence.Version;

@Entity
@Table(name="TB_CANZONE")
public class Canzone extends CommonClass {

	@Id
	@GeneratedValue(strategy=GenerationType.AUTO)
	@Column(name="NUM_CANZONE")
	Long id;
	@ManyToOne(fetch = FetchType.EAGER, optional = false)
	@JoinColumn(name="NUM_ARTISTA")
	Artista artista;
	@Lob
	@Column(name="TXT_TESTO")
	String testo;
	@Column(name="TXT_TITOLO")
	String titolo;
	@Column(name="NUM_TRACCIA")
	Integer traccia;
	@Column(name="TS_CREATION_DATE")
	Date creationDate;
	@Column(name="TS_LAST_UPDATE_DATE")
	Date lastUpdateDate;
	@Column(name="TXT_MBID")
	String mbid;
	
	@Version
	@Column(name="NUM_VERSION")
	Long version;
	
	public Long getVersion() {
		return version;
	}
	public void setVersion(Long version) {
		this.version = version;
	}
	@PrePersist
	public void creationDate(){
		creationDate = new Date();
		lastUpdateDate = null;
	}
	@PreUpdate
	public void lastUpdateDate(){
		lastUpdateDate = new Date();
	}
	
	public Long getId() {
		return id;
	}
	public void setId(Long id) {
		this.id = id;
	}
	public Artista getArtista() {
		return artista;
	}
	public void setArtista(Artista artista) {
		this.artista = artista;
	}
	public String getTesto() {
		return testo;
	}
	public void setTesto(String testo) {
		this.testo = testo;
	}
	public String getTitolo() {
		return titolo;
	}
	public void setTitolo(String titolo) {
		this.titolo = titolo;
	}
	public Date getCreationDate() {
		return creationDate;
	}
	public void setCreationDate(Date creationDate) {
		this.creationDate = creationDate;
	}
	public Date getLastUpdateDate() {
		return lastUpdateDate;
	}
	public void setLastUpdateDate(Date lastUpdateDate) {
		this.lastUpdateDate = lastUpdateDate;
	}
	public Integer getTraccia() {
		return traccia;
	}
	public void setTraccia(Integer traccia) {
		this.traccia = traccia;
	}
	public String getMbid() {
		return mbid;
	}
	public void setMbid(String mbid) {
		this.mbid = mbid;
	}
}
